/**
 * @file   irenderer.h
 * @Author Alexandre Chassany (alexandre.chassany@gmail.com)
 * @date   March 2011
 * @brief  Base interface for renderer
 *
 * Poum-tchak is a free sound manipulation and synthesis, 
 * real-time and interactive music-clip rendering.
 *
 * Copyright (C) 2011  Chassany Alexandre and Gonzalez Antoine.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * he Free Software Foundation, either version 3 of the License, or
 * at your option) any later version.
 *
 * is program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef _ELIXIR_IRENDERER_H_
#define _ELIXIR_IRENDERER_H_

#include <renderer/bufferguard.h>
#include <renderer/ideclaration.h>
#include <renderer/enum.h>

namespace Elixir
{

  /**
   * @class IRenderer
   * @brief Base interface for renderers
   */
  class IRenderer
  {
  public :

	IRenderer();

	virtual ~IRenderer();

	/**
	 * @bief initialize the renderer
	 */
	virtual void initialize() = 0;

	/**
	 * @brief begin the render of the scene
	 * @details call this methode before drawing any objects
	 */
	virtual void beginScene() const = 0;

	/**
	 * @brief end the render of the scene
	 * @details once you have draw all the objects of your scene
	 * call this methode to end the drawing.
	 */
	virtual void endScene() const = 0;

	virtual IBufferBase* createVB(unsigned long size, unsigned long stride, unsigned long flags) const = 0;
	virtual IBufferBase* createIB(unsigned long size, unsigned long stride, unsigned long flags) const = 0;
	virtual IDeclaration* createDeclaration(const DeclarationElement* elements, std::size_t count) const = 0;
	virtual void setVB(unsigned int stream, const IBufferBase* buffer, unsigned long stride, unsigned long min_vertex, unsigned long max_vertex) = 0;
	virtual void setIB(const IBufferBase* buffer, unsigned long stride) = 0;
	virtual void setDeclaration(const IDeclaration* declaration) = 0;

	virtual void drawPrimitives(PrimitiveType type, unsigned long firstVertex, unsigned long count) const = 0;
	virtual void drawIndexedPrimitives(PrimitiveType type, unsigned long firstIndex, unsigned long count) const = 0;

  public:
	template<class T>
	  BufferGuard<T> createVertexBuffer(unsigned long size, unsigned long flags, const T* data = NULL) const;

	template<class T>
	  BufferGuard<T> createIndexBuffer(unsigned long size, unsigned long flags, const T* data = NULL) const;

	template<class T>
	  void setVertexBuffer(unsigned int stream, const BufferGuard<T>& buffer, unsigned long min_vertex = 0, unsigned long max_vertex = 0);
	
	template<class T>
	  void setIndexBuffer(const BufferGuard<T>& buffer);

	template<std::size_t N> 
	  IDeclaration* createVertexDeclaration(const DeclarationElement (&elements)[N]) const;
  };

  #include "irenderer-inl.h"
}


#endif // _ELIXIR_IRENDERER_H_
